cmake_minimum_required(VERSION 2.6)
project( woptions )

# Check for out-of-source builds so that we don't overwrite the makefile
# provided with woptions
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
get_filename_component(PARENTDIR ${CMAKE_SOURCE_DIR} PATH)
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PARENTDIR}" insourcesubdir)
if(insource OR insourcesubdir)
	message(FATAL_ERROR "woptions requires an out-of-source build")
endif()

# Find Boost
set(Boost_ADDITIONAL_VERSIONS 1.37 1.38)
find_package( Boost 1.37 REQUIRED unit_test_framework )
include_directories( ${Boost_INCLUDE_DIRS} )

include_directories( . )

# Add the woptions library
file(GLOB WOPTIONS_SRCS . woptions/*.cpp)
file(GLOB WOPTIONS_HDRS . woptions/*.h)
add_library( woptions STATIC ${WOPTIONS_SRCS} )

# Add the woptions regression tests
file(GLOB TESTS_SRCS . tests/*.cpp)
add_executable( woptions-tests ${TESTS_SRCS} )
target_link_libraries( woptions-tests woptions ${Boost_LIBRARIES} )
add_test( run-woptions-tests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/woptions-tests )	

file(GLOB EXAMPLE_SRCS . examples/*.cpp)
foreach( example ${EXAMPLE_SRCS} )
	get_filename_component(example_name ${example} NAME_WE)
	set( example_name woptions-${example_name} )
	add_executable( ${example_name} ${example} )
	target_link_libraries( ${example_name} woptions )
endforeach()

find_package( Doxygen )
if( DOXYGEN_FOUND )
	add_custom_target( woptions-docs
		COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
		COMMENT "Generating documentation"
		WORKING_DIRECTORY ${woptions_SOURCE_DIR}
	)
endif()
